/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.schema.fetcher;

import com.eng.scc.core.data.Address;
import com.eng.scc.core.db.Database;
import com.eng.scc.core.db.Fetcher;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Rafael
 */
public class AddressFetcher implements Fetcher<Address>
{
    @Override
    public Address fetch( ResultSet ps ) throws Exception
    {
        Address address = new Address();
        
        address.setId( ps.getInt( 1 ) );
        address.setCityId( ps.getInt( 2 ) );
        address.setHomeState( ps.getInt( 3 ) );
        address.setCountry( ps.getString( 4 ) );
        address.setName( ps.getString( 5 ) );
        address.setNumber( ps.getString( 6 ) );
        address.setCep( ps.getString( 7 ) );
        
        return address;
    }

    @Override
    public void insert( Address value, PreparedStatement ps ) throws Exception
    {
        value.setId( Database.getInstance().nextID( "core_addresses" ) );
        
        ps.setInt( 1, value.getId() );
        ps.setInt( 2, value.getCityId() );
        ps.setInt( 3, value.getHomeState() );
        ps.setString( 4, value.getCountry() );
        ps.setString( 5, value.getName() );
        ps.setString( 6, value.getNumber() );
        ps.setString( 7, value.getCep() );
    }

    @Override
    public void update( Address value, PreparedStatement ps ) throws Exception
    {
        ps.setInt( 1, value.getCityId() );
        ps.setInt( 2, value.getHomeState() );
        ps.setString( 3, value.getCountry() );
        ps.setString( 4, value.getName() );
        ps.setString( 5, value.getNumber() );
        ps.setString( 6, value.getCep() );
        
        ps.setInt( 7, value.getId() );
    }
    
}
